<%@ page contentType="text/html;charset=UTF-8" language="java"  import="com.lkqandzzy.entity.Student" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<html>
<head>
    <title>后台登录</title>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <%--<meta http-equiv="Cache-Control" content="no-siteapp" />--%>

    <link rel="icon" href="images/favicon.ico" sizes="32x32" />
    <link rel="stylesheet" href="css/font.css">
    <link rel="stylesheet" href="css/xadmin.css">
    <script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
    <script src="lib/layui/layui.js"></script>
    <script type="text/javascript" src="js/xadmin.js"></script>
    <script src="layui_exts/excel.js"></script>

    <style type="text/css">
        .layui-table{
            background-color: rgba(55,12,195,.14);
            color: #2E2D3C;
            font-size: 50px;
            text-align: center;
        }
        .layui-table th{
            font-family: 'DFKai-SB';
            font-size: 25px;
            text-align: center;
            background-color: rgba(165,123,123,.4);
        }
        .layui-table td {
            font-family: 'DFKai-SB';
            font-size: 25px;
            text-align: center;
            background-color: rgba(165,123,123,.4);
        }
        xblock{
            background-color: rgba(133,24,171,.31);
            border-radius: 10px;
        }
        body{
            background: url("images/2.png") no-repeat;
            height: auto;
            background-size: cover;
        }
        .layui-row input{
            background-color: rgba(255,255,255,.7);
            font-family: 'DFKai-SB';
            font-size: 15px;
        }

    </style>
</head>

<body>
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="${pageContext.request.contextPath}/findOpportunities">销售机会</a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="${pageContext.request.contextPath}/findOpportunities" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body">
    <div class="layui-row">
        <form class="layui-form layui-col-md12 x-so" action="${pageContext.request.contextPath}/findOpportunities" >
            <input class="layui-input" placeholder="请输入联系人" name="contacts" id="contacts">
            <input class="layui-input" placeholder="请输入状态" name="state" id="state">


            <input class="layui-input" type="hidden" name="pageIndex" value="1">
            <input class="layui-input" type="hidden" name="pageSize" value="10">
            <button class="layui-btn"  lay-submit="" lay-filter="search"><i class="layui-icon">&#xe615;</i></button>
        </form>
    </div>
    <xblock>
        <button id="addStudnetBtn" class="layui-btn layui-btn-normal"> <i class="layui-icon">&#xe654;</i>添加 </button>
        <button class="layui-btn layui-btn-warm" lay-filter="toolbarDemo" lay-submit=""><i class="layui-icon">&#xe67c;</i>导出</button>
        <span class="x-right" style="line-height:40px">共有数据：${hi.totalCount} 条</span>
    </xblock>

    <%--添加模态框--%>
    <div class="layui-row" id="test" style="display: none;">
        <div class="layui-col-md10">
            <form class="layui-form" id="addEmployeeForm">
                <div class="layui-form-item">
                    <label class="layui-form-label">主题：</label>
                    <div class="layui-input-block">
                        <input type="text" lay-verify="required" name="theme"   class="layui-input" placeholder="请输入主题">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">客户名称：</label>
                    <div class="layui-input-block">
                        <input type="text" lay-verify="required" name="customer_name"  class="layui-input" placeholder="请输入姓名">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">联系人：</label>
                    <div class="layui-input-block">
                        <input type="text" lay-verify="required" name="contacts"  class="layui-input" placeholder="请输入联系人">
                    </div>
                </div>



                <div class="layui-form-item">
                    <label class="layui-form-label">发现时间：</label>
                    <div class="layui-input-block">
                        <input type="text" name="discovery_time" class="layui-input" i placeholder="请输入发现时间">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">客户需求：</label>
                    <div class="layui-input-block">
                        <input type="text"  name="c_demand"  class="layui-input" placeholder="请输客户需求">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">预计签单时间：</label>
                    <div class="layui-input-block">
                        <input type="text" name="e_signature" class="layui-input" placeholder="请输入预计时间">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">预计金额：</label>
                    <div class="layui-input-block">
                        <input type="text" name="e_amount" class="layui-input" placeholder="请输入金额">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">可能性：</label>
                    <div class="layui-input-block">
                        <input type="text" name="possibility" class="layui-input" placeholder="请输入可能性">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">当前阶段：</label>
                    <div class="layui-input-block">
                        <input type="text" name="current_stage" class="layui-input" placeholder="请输入当前阶段">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">状态：</label>
                    <div class="layui-input-block">
                        <input type="text" name="state" class="layui-input" placeholder="请输入状态">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">建档人：</label>
                    <div class="layui-input-block">
                        <input type="text" name="a_person" class="layui-input" placeholder="请输入建档人">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">建档时间：</label>
                    <div class="layui-input-block">
                        <input type="text" name="filing_time" class="layui-input" placeholder="请输入建档时间">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button type="button" class="layui-btn layui-btn-normal" lay-submit lay-filter="formDemo">提交</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>
            </form>

            </form>
        </div>
    </div>

    </form>
</div>
</div>


<%--表格数据--%>
<table class="layui-table">
    <thead>
    <tr>
        <%--<th>--%>
        <%--<div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i class="layui-icon">&#xe605;</i></div>--%>
        <%--</th>--%>
            <th>ID</th>
            <th>机会主题</th>
            <th>客户名称</th>
            <th>联系人</th>
            <th>发现时间</th>
            <th>客户需求</th>
            <th>预计签单时间</th>
            <th>预计金额</th>
            <th>可能性</th>
            <th>当前阶段</th>
            <th>状态</th>
            <th>建档人</th>
            <th>建档时间</th>
            <th>操作</th>
    </thead>
    <tbody>
    <c:forEach items="${hi.list}" var="hi">
        <tr>
                <%--<td>--%>
                <%--<div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='2'><i class="layui-icon">&#xe605;</i></div>--%>
                <%--</td>--%>
                    <td>${hi.sales_id}</td>
                    <td>${hi.theme}</td>
                    <td>${hi.customer_name}</td>
                    <td>${hi.contacts}</td>
                    <td>${hi.discovery_time}</td>
                    <td>${hi.c_demand}</td>
                    <td>${hi.e_signature}</td>
                    <td>${hi.e_amount}</td>
                    <td>${hi.possibility}%</td>
                    <td>${hi.current_stage}</td>
                    <td>${hi.state}</td>
                    <td>${hi.a_person}</td>
                    <td>${hi.filing_time}</td>
            <td>
                <a title="编辑" id= "updateEdit" href="${pageContext.request.contextPath}/findOpportunitiesById?sales_id=${hi.sales_id}">
                    <i class="layui-icon">&#xe642;</i>
                </a>
                <a title="删除" onclick="member_del(this,'${hi.sales_id}')" href="javascript:;">
                    <i class="layui-icon">&#xe640;</i>
                </a>
            </td>
        </tr>
    </c:forEach>
    </tbody>
</table>

<div class="" >
    <input type="hidden" id="totalPageCount" value="${hi.pageTotalCount}"/>
    <c:import url="pageBtn.jsp">
        <c:param name="totalCount" value="${hi.totalCount}"/>
        <c:param name="currentPageNo" value="${hi.pageIndex}"/>
        <c:param name="totalPageCount" value="${hi.pageTotalCount}"/>
    </c:import>
</div>
</div>
<script>

    layui.config({
        base: 'layui_exts/',
    }).extend({
        excel: 'excel',
    });

    layui.use(['jquery', 'excel','form','layer','laydate'], function(){
        var form = layui.form,
            $ = layui.jquery,
            laydate = layui.laydate;
        var excel = parent.layui.excel;

        //执行一个laydate实例
        laydate.render({
            elem: '#start' //指定元素
        });

        form.on('submit(toolbarDemo)', function(){

            $.ajax({
                url: '${pageContext.request.contextPath}/exportOpportunities',
                type: 'post',
                dataType: 'json',
                contentType: "application/json; charset=utf-8",
                success: function (data) {
                    console.log(data);

                    // 1. 如果需要调整顺序，请执行梳理函数
                    var dt = excel.filterExportData(data, [
                        'sales_id'
                        ,'theme'
                        ,'customer_name'
                        ,'contacts'
                        ,'discovery_time'
                        ,'c_demand'
                        ,'e_signature'
                        ,'e_amount'
                        ,'possibility'
                        ,'current_stage'
                        ,'state'
                        ,'a_person'
                        ,'filing_time'
                    ]);

                    // 2. 数组头部新增表头
                    dt.unshift({sales_id: 'ID', theme: '机会主题', customer_name: '客户名称', contacts: '联系人', discovery_time: '发现时间', c_demand: '客户需求',
                        e_signature: '预计签单时间',e_amount: '预计金额',possibility: '可能性',current_stage: '当前阶段',state: '状态',
                        a_person: '建档人',filing_time: '建档时间'});

                    // 意思是：A列40px，B列60px(默认)，C列120px，D、E、F等均未定义
                    var colConf = excel.makeColConfig({
                        'B': 90,
                        'C': 80,
                        'F': 90
                    }, 60);

                    var timestart = Date.now();
                    // 3. 执行导出函数，系统会弹出弹框
                    excel.exportExcel({
                        sheet1: dt
                    }, '学生数据.xlsx', 'xlsx', {
                        extend: {
                            '!cols': colConf
                        }
                    });
                    var timeend = Date.now();

                    var spent = (timeend - timestart) / 1000;
                    layer.alert('导出耗时 '+spent+' s');
                    //setTimeout(function () {window.location.href='/findAdmin';},2000);
                },

                error: function () {
                    //console.log(data);
                    setTimeout(function () {window.location.href='${pageContext.request.contextPath}/finOpportunities';},2000);
                }
            });
        });

        /*添加弹出框*/
        $("#addStudnetBtn").click(function () {
            layer.open({
                type:1,
                title:"添加学生",
                skin:"myclass",
                area:["50%"],
                anim:2,
                content:$("#test").html()
            });
            $("#addEmployeeForm")[0].reset();
            form.on('submit(formDemo)', function(data) {
                // layer.msg('aaa',{icon:1,time:3000});
                var param=data.field;
                // console.log(JSON.stringify(param));
                $.ajax({
                    url: '${pageContext.request.contextPath}/addOpportunities',
                    type: "post",
                    data:JSON.stringify(param),
                    contentType: "application/json; charset=utf-8",
                    success:function(){
                        layer.msg('添加成功', {icon: 1, time: 3000});
                        setTimeout(function () {window.location.href='${pageContext.request.contextPath}/findOpportunities';},2000);

                    },
                    error:function(){
                        layer.msg('添加失败',{icon:0,time:3000});
                        setTimeout(function () {window.location.href='${pageContext.request.contextPath}/findOpportunities';},2000);
                    }
                });
                // return false;
            });
        });


    });



    /*删除*/
    function member_del(obj,sales_id){
        layer.confirm('确认要删除吗？',function(index){
            //发异步删除数据
            $.get("${pageContext.request.contextPath}/deleteOpportunities",{"sales_id":sales_id},function (data) {
                if(data =true){
                    layer.msg('删除成功!',{icon:1,time:2000});
                    setTimeout(function () {window.location.href='${pageContext.request.contextPath}/findOpportunities';},2000);

                }else {
                    layer.msg('删除失败!',{icon:1,time:3000});
                    setTimeout(function () {window.location.href='${pageContext.request.contextPath}/findOpportunities';},2000);
                }
            });
        });
    }

</script>


</body>


</html>
